﻿using BCCommon;
using BCDto.CRM.BigCustomerGroup;
using BCService.CRM.BigCustomerGroup;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.CRM.BigCustomerGroup
{
    [ApiExplorerSettings(GroupName = "CRMAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class BigCustomerGroupController : ManagementBaseController
    {
        #region var
        private IBigCustomerGroupService bigCustomerGroupService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public BigCustomerGroupController(IBigCustomerGroupService bigCustomerGroupService)
        {
            this.bigCustomerGroupService = bigCustomerGroupService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新大客户组纪录
        /// </summary>
        /// <param name="dto">大客户组数据模型</param>
        /// <returns></returns>
        [Log("添加新大客户组纪录")]
        [HttpPost]
        [ProducesResponseType(typeof(BigCustomerGroupRequestDto), 200)]
        public IActionResult Post([FromBody] BigCustomerGroupRequestDto dto)
        {
            var a = bigCustomerGroupService.Add(dto, this.Admin);
            return Ok(a);
        }

        #endregion

        #region PUT 修改   
        /// <summary>
        /// 修改大客户组纪录
        /// </summary>
        /// <param name="dto">大客户组数据修改模型</param>
        /// <returns></returns>
        [Log("修改大客户组纪录")]
        [HttpPut]
        [ProducesResponseType(typeof(BigCustomerGroupDto), 200)]
        public IActionResult Put([FromBody] BigCustomerGroupPutDto dto)
        {
            var a = Ok(bigCustomerGroupService.Update(dto, this.Admin));
            return a;
        }
        #endregion

        #region 删除  
        /// <summary>
        /// 删除大客户组纪录
        /// </summary>
        /// <param name="bigCustomerGroupId">大客户组ID</param>
        /// <returns></returns>
        [Log("删除大客户组纪录")]
        [HttpDelete("{big_customer_group_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "big_customer_group_id")] long bigCustomerGroupId)
        {
            bigCustomerGroupService.Delete(bigCustomerGroupId);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条大客户组纪录
        /// </summary>
        /// <param name="bigCustomerGroupId">大客户组ID</param>
        /// <returns></returns>
        [HttpGet("{big_customer_group_id}")]
        [ProducesResponseType(typeof(BigCustomerGroupDto), 200)]
        public IActionResult Get([FromRoute(Name = "big_customer_group_id")] long bigCustomerGroupId)
        {
            return (Ok(bigCustomerGroupService.GetById(bigCustomerGroupId)));

        }
        #endregion

        #region Query 
        /// <summary>
        /// 查询大客户组
        /// </summary>
        /// <param name="bigCustomerGroupName">大客户组名</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页记录数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<BigCustomerGroupDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "big_customer_group_name")] string bigCustomerGroupName,
            [FromQuery(Name = "index")] int? pageIndex = 1,
            [FromQuery(Name = "size")] int? pageSize = 10)
        {
            var a = Ok(bigCustomerGroupService.GetList(Admin,bigCustomerGroupName,pageIndex.Value, pageSize.Value));
            return a;
        }
        #endregion

        #region 获取大客户组列表
        /// <summary>
        /// 获取大客户组列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<BigCustomerGroupDto>), 200)]
        public IActionResult QueryOnlyList()
        {
            var a = Ok(bigCustomerGroupService.GetOnlyList(Admin));
            return a;
        } 
        #endregion
    }

}
